<?php
/**
 * Created by PhpStorm.
 * User: meng
 * Date: 2023/9/22
 * Time: 16:11
 */

namespace bootstrap;

use support\Log;
use think\facade\Db;
use Webman\Bootstrap;
use Workerman\Timer;
use Workerman\Worker;

class ThinkOrmLog implements Bootstrap
{

    public static function start (?Worker $worker) {
        if (config('thinkorm.connections.mysql.trigger_sql') && config('app.debug')) {
            Db::listen(function ($sql) {
                Log::channel('sql')->debug($sql);
            });
        }
        // 心跳
        Timer::add(30, function () {
            Db::query('select 1 limit 1');
        });
    }
}
